package com.ruoyi.web.controller.safety;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.safety.domain.SystemCodeDict;
import com.ruoyi.safety.service.ISystemCodeDictService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系统编码字典Controller
 * 
 * @author ruoyi
 * @date 2024-11-06
 */
@RestController
@RequestMapping("/safety/systemCodeDict")
public class SystemCodeDictController extends BaseController
{
    @Autowired
    private ISystemCodeDictService systemCodeDictService;

    /**
     * 查询系统编码字典列表
     */
    @PreAuthorize("@ss.hasPermi('safety:dict:list')")
    @GetMapping("/list")
    public TableDataInfo list(SystemCodeDict systemCodeDict)
    {
        startPage();
        List<SystemCodeDict> list = systemCodeDictService.selectSystemCodeDictList(systemCodeDict);
        return getDataTable(list);
    }

    /**
     * 导出系统编码字典列表
     */
    @PreAuthorize("@ss.hasPermi('safety:dict:export')")
    @Log(title = "系统编码字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SystemCodeDict systemCodeDict)
    {
        List<SystemCodeDict> list = systemCodeDictService.selectSystemCodeDictList(systemCodeDict);
        ExcelUtil<SystemCodeDict> util = new ExcelUtil<SystemCodeDict>(SystemCodeDict.class);
        util.exportExcel(response, list, "系统编码字典数据");
    }

    /**
     * 获取系统编码字典详细信息
     */
    @PreAuthorize("@ss.hasPermi('safety:dict:query')")
    @GetMapping(value = "/{systemId}")
    public AjaxResult getInfo(@PathVariable("systemId") String systemId)
    {
        return success(systemCodeDictService.selectSystemCodeDictBySystemId(systemId));
    }

    /**
     * 新增系统编码字典
     */
    @PreAuthorize("@ss.hasPermi('safety:dict:add')")
    @Log(title = "系统编码字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SystemCodeDict systemCodeDict)
    {
        return toAjax(systemCodeDictService.insertSystemCodeDict(systemCodeDict));
    }

    /**
     * 修改系统编码字典
     */
    @PreAuthorize("@ss.hasPermi('safety:dict:edit')")
    @Log(title = "系统编码字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SystemCodeDict systemCodeDict)
    {
        return toAjax(systemCodeDictService.updateSystemCodeDict(systemCodeDict));
    }

    /**
     * 删除系统编码字典
     */
    @PreAuthorize("@ss.hasPermi('safety:dict:remove')")
    @Log(title = "系统编码字典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{systemIds}")
    public AjaxResult remove(@PathVariable String[] systemIds)
    {
        return toAjax(systemCodeDictService.deleteSystemCodeDictBySystemIds(systemIds));
    }
}
